package com.app.ytong.bean;


import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.ArrayList;
import java.util.List;

import my.MathUtils;

public class GoodsTypeListBean extends BaseListBean {



    private ArrayList<GoodsTypeListData> list = new ArrayList<GoodsTypeListData>();

    public ArrayList<GoodsTypeListData> getList() {
        return list;
    }

    public void setList(ArrayList<GoodsTypeListData> list) {
        this.list = list;
    }

    @JSONField(serialize = false)
    public void addListBean(GoodsTypeListBean listbean) {
        if (listbean == null)
            return;
        if (this.getCurrentPage() == INIT_PAGE) {
            setList(listbean.getList());
        } else {
            if (list == null)
                list = new ArrayList<GoodsTypeListData>();
            list.addAll(listbean.getList());
        }
        setListBeanData(listbean);
    }

    @JSONField(serialize = false)
    public List<String> getAllName(){
        List<String> nameList = new ArrayList<>();
        for (GoodsTypeListData data : list){
            nameList.add(data.getTna());
        }
        return nameList;
    }

    @JSONField(serialize = false)
    public String getTidByPosition(int position){
        if(list == null || list.size()<1){
            return "";
        }

       return list.get(position).getTid();
    }

    @JSONField(serialize = false)
    public void AllDefaultSelect(){
        for (GoodsTypeListData data : list){
            data.setSelect(false);
        }
    }

    @JSONField(serialize = false)
    public void setDefaultSelectExcept(GoodsTypeListData other){
        for (GoodsTypeListData data : list){
            if(data != other){
                data.setSelect(false);
            }
        }
    }

    @JSONField(serialize = false)
    public String getTidByName(String name){
        for (GoodsTypeListData data : list){
            if(name.equals(data.getTna())){
                return data.getTid();
            }
        }
        return "";
    }

    @JSONField(serialize = false)
    public boolean getAllTraIsEmpty(){
        for (GoodsTypeListData data : list){
            if(!TextUtils.isEmpty(data.getEditTra())){
                return false;
            }
        }
        return true;
    }


    @JSONField(serialize = false)
    public void setTra(SupplierListData supplierListData){
        for (GoodsTypeListData data : list){
            for (TraceListData traceListData : supplierListData.getTracelist()){
                if(data.getTid().equals(traceListData.getTid())){
                    data.setTra(traceListData.getTra());
                }
            }
        }
    }


    @JSONField(serialize = false)
    public  String getEditTraByTid(String tid){
        String tra = "0";
        for (GoodsTypeListData data : list){
            if(tid.equals(data.getTid())){
                tra = MathUtils.add(tra,data.getEditTra());
            }
        }
        return tra;
    }

    @JSONField(serialize = false)
    public  String getTnaByTid(String tid){
        for (GoodsTypeListData data : list){
            if(tid.equals(data.getTid())){
               return data.getTna();
            }
        }
        return "";
    }
}
